﻿@*------------------------------------------------------------
  Copyright (c) Microsoft Corporation.  All rights reserved.
  Licensed under the MIT License (MIT). See License.txt in the repo root for license information.
 ------------------------------------------------------------*@

@page "/assetLogin"

@using Microsoft.Azure.IIoT.App.Common;
@using Microsoft.AspNetCore.DataProtection;
@using Microsoft.Azure.IIoT.App.Services.SecureData;

@inject Blazored.SessionStorage.ISessionStorageService sessionStorage
@inject IDataProtectionProvider provider
@inject UICommon CommonHelper
@inject SecureData secureData

<h1>Login</h1>

@if (ShowLogin)
{
    <div class="col-md-12">
        <h1 class="h3 mb-3 font-weight-normal">Please Sign In</h1>
    </div>

    <EditForm Model="@Credential" OnValidSubmit=@(async() => await SignInAsync())>
        <DataAnnotationsValidator />
        <ValidationSummary />
        <div class="col-md-12 form-group">
            <div class="col-md-6 input-group">
                <span class="input-group-addon"><i class="glyphicon glyphicon-user"></i></span>
                <InputText @bind-Value="Credential.Username" class="form-control" id="username"
                           placeholder="Enter UserName" title="Enter UserName" />
            </div>
        </div>
        <div class="col-md-12 form-group">
            <div class="col-md-6 input-group">
                <span class="input-group-addon"><i class="glyphicon glyphicon-lock"></i></span>
                <input type="password" @bind-value="Credential.Password" class="form-control" id="password"
                       placeholder="Enter Password" title="Enter Password" />
            </div>
        </div>

        <button type="submit" class="btn btn-primary shadow-none">Login</button>
    </EditForm>
}
else
{
    <div class="col-md-12">
        <h1 class="h3 mb-3 font-weight-normal">Hello, @Credential.Username</h1>
    </div>

    <button @onclick="SignOutAsync" class="btn btn-primary shadow-none">Logout</button>
}